package com.luyuan.web.controller.gallery;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luyuan.common.annotation.Log;
import com.luyuan.common.core.controller.BaseController;
import com.luyuan.common.core.domain.AjaxResult;
import com.luyuan.common.enums.BusinessType;
import com.luyuan.gallery.domain.ExhiArtwork;
import com.luyuan.gallery.service.IExhiArtworkService;
import com.luyuan.gallery.vo.ExhiArtworkVO;
import com.luyuan.common.utils.poi.ExcelUtil;
import com.luyuan.common.core.page.TableDataInfo;

/**
 * 作品Controller
 * 
 * @author luyuan
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/gallery/artwork")
public class ExhiArtworkController extends BaseController {
    @Autowired
    private IExhiArtworkService exhiArtworkService;

    /**
     * 查询作品列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:artwork:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExhiArtwork exhiArtwork) {
        startPage();
        List<ExhiArtworkVO> list = exhiArtworkService.selectExhiArtworkList(exhiArtwork);
        return getDataTable(list);
    }

    /**
     * 导出作品列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:artwork:export')")
    @Log(title = "作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExhiArtwork exhiArtwork) {
        List<ExhiArtworkVO> list = exhiArtworkService.selectExhiArtworkList(exhiArtwork);
        ExcelUtil<ExhiArtworkVO> util = new ExcelUtil<ExhiArtworkVO>(ExhiArtworkVO.class);
        util.exportExcel(response, list, "作品数据");
    }

    /**
     * 获取作品详细信息
     */
    @PreAuthorize("@ss.hasPermi('gallery:artwork:query')")
    @GetMapping(value = "/{artworkId}")
    public AjaxResult getInfo(@PathVariable("artworkId") Long artworkId) {
        return success(exhiArtworkService.selectExhiArtworkByArtworkId(artworkId));
    }

    /**
     * 新增作品
     */
    @PreAuthorize("@ss.hasPermi('gallery:artwork:add')")
    @Log(title = "作品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExhiArtwork exhiArtwork) {
        return toAjax(exhiArtworkService.insertExhiArtwork(exhiArtwork));
    }

    /**
     * 修改作品
     */
    @PreAuthorize("@ss.hasPermi('gallery:artwork:edit')")
    @Log(title = "作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExhiArtwork exhiArtwork) {
        return toAjax(exhiArtworkService.updateExhiArtwork(exhiArtwork));
    }

    /**
     * 删除作品
     */
    @PreAuthorize("@ss.hasPermi('gallery:artwork:remove')")
    @Log(title = "作品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{artworkIds}")
    public AjaxResult remove(@PathVariable Long[] artworkIds) {
        return toAjax(exhiArtworkService.deleteExhiArtworkByArtworkIds(artworkIds));
    }
}
